package com.freewater.springboot.demo.aop.api.pointcut;

import org.springframework.aop.support.DynamicMethodMatcherPointcut;
import org.springframework.lang.NonNull;

import java.lang.reflect.Method;

public class SimpleDynamicMethodPointcut extends DynamicMethodMatcherPointcut {

    @Override
    public boolean matches(@NonNull Method method, @NonNull Class<?> targetClass, Object... args) {
        // 匹配add方法
        Integer sum = 0;
        for (Object arg : args) {
            Integer a = (Integer) arg;
            sum += a;
        }
        return method.getName().equals("add") && sum > 50;
    }
}
